package com.starlink.service.impl;

import cn.hutool.core.convert.Convert;
import cn.xuyanwu.spring.file.storage.FileInfo;
import cn.xuyanwu.spring.file.storage.FileStorageService;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.stupdit1t.excel.common.Col;
import com.github.stupdit1t.excel.common.PoiResult;
import com.github.stupdit1t.excel.core.ExcelHelper;
import com.starlink.client.ras.RasClient;
import com.starlink.client.ras.request.GoodsAddRequest;
import com.starlink.client.ras.request.GoodsListEvidenceRequest;
import com.starlink.client.ras.response.GoodsListEvidenceResponse;
import com.starlink.client.ras.response.RasBaseResponse;
import com.starlink.common.PageInfoTwo;
import com.starlink.common.enums.ErrorCode;
import com.starlink.common.exception.BusinessException;
import com.starlink.common.utils.AssertUtil;
import com.starlink.context.SessionContext;
import com.starlink.mapper.*;
import com.starlink.model.domain.*;
import com.starlink.model.dtomapper.MallBooksDetailDtoMapper;
import com.starlink.model.dtomapper.MallBooksDtoMapper;
import com.starlink.model.dtomapper.MallBooksSpecificationDtoMapper;
import com.starlink.model.excel.MallBookDetailExcelDTO;
import com.starlink.model.excel.MallBookExcelDTO;
import com.starlink.model.excel.MallBookSpecificationExcelDTO;
import com.starlink.model.request.MallBooksDetailAddRequest;
import com.starlink.model.request.MallBooksDetailRequest;
import com.starlink.model.request.MallBooksRequest;
import com.starlink.model.request.mall.EntryData;
import com.starlink.model.request.save.MallBooksSaveRequest;
import com.starlink.model.request.save.MallBooksSpecificationSaveRequest;
import com.starlink.model.util.MallBooksConvert;
import com.starlink.model.vo.MallBooksVO;
import com.starlink.model.vo.MallCategoryVO;
import com.starlink.service.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import javax.sql.DataSource;
import java.io.IOException;
import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;

import static com.starlink.utils.IDUtils.getId;
import static com.starlink.utils.PageUtils.getOrderBy;

/**
 * @author zhanghong
 */
@Slf4j
@Service
public class MallBooksServiceImpl extends ServiceImpl<MallBooksMapper, MallBooksDO> implements MallBooksService {
    @Autowired
    private MallBooksMapper mallBooksMapper;
    @Autowired
    private MallBooksService mallBooksService;
    @Autowired
    private MallBooksSpecificationService specificationService;
    @Autowired
    private MallBooksDetailService booksDetailService;
    @Autowired
    private MallCategoryService mallCategoryService;
    @Autowired
    private MallBooksDetailMapper detailMapper;
    @Autowired
    private MallBooksCategoryMapper booksCategoryMapper;
    @Autowired
    private MallBooksSpecificationMapper specificationMapper;
    @Autowired
    private MallIntegrationMapper mallIntegrationMapper;
    @Autowired
    private RasClient rasClient;
    @Autowired
    private MallBooksRasService mallBooksRasService;
    @Autowired
    private MallOrderDetailsService bookOrderDetailsService;
    @Autowired
    private ShoppingCartOrderDetailsService cartOrderDetailsService;
    @Autowired
    private MallIntegrationOrderService integrationOrderService;
    @Autowired
    private SchoolbagBooksService schoolbagBooksService;
    @Autowired
    private FreeTemplateService freeTemplateService;
    @Autowired
    private FileStorageService fileStorageService;
    @Override
    public MallBooksVO getByKey(long id) {
        MallBooksVO mallBooksVO = MallBooksDtoMapper.INSTANCE.do2VO(getById(id));
        return mallBooksVO;
    }

    @Override
    public PageInfoTwo<MallBooksVO> pageQuery(MallBooksRequest request) {
        long count = mallBooksMapper.pageCount(request);
        List<MallBooksVO> list = mallBooksMapper.pageQuery(request, request.getPageSize(), request.fetchOffSet());
        return new PageInfoTwo(request.getPageNum(), request.getPageSize(), list, count);
    }

    @Override
    public List<MallBooksVO> listQuery(MallBooksRequest request) {
        List<MallBooksDO> list = mallBooksMapper.selectDOList(MallBooksDtoMapper.INSTANCE.request2DO(request));
        List<MallBooksVO> mallBooksVOS = MallBooksConvert.buildMallBooksVoList(list);
        return mallBooksVOS;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean add(MallBooksSaveRequest request) {
        MallBooksDO entity = MallBooksDtoMapper.INSTANCE.request2DO(request);
        entity.setId(getId());
        save(entity);
        request.setId(entity.getId());
        return true;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean updateByKey(MallBooksSaveRequest request) {
        Long rasGoodsId = request.getRasGoodsId();
        AssertUtil.assertNotNull(request.getId(), "id不能为空!");
        AssertUtil.assertNotNull(rasGoodsId, "RAS商品ID不能为空!");
        GoodsListEvidenceRequest evidenceRequest = new GoodsListEvidenceRequest();
        evidenceRequest.setId(rasGoodsId.intValue());
        RasBaseResponse<GoodsListEvidenceResponse> goodsListEvidence = rasClient.goodsListEvidence(evidenceRequest);
        GoodsListEvidenceResponse listEvidenceData = goodsListEvidence.getData();
        GoodsListEvidenceResponse.RasGoodsListPageDTO rasGoodsListPage = listEvidenceData.getRasGoodsListPage();
        List<GoodsListEvidenceResponse.RasGoodsListPageDTO.RecordsDTO> records = rasGoodsListPage.getRecords();
        AssertUtil.assertNotEmpty(records,"该书籍RAS审核还未通过,暂不能上架!");
        saveOrUpdate(MallBooksDtoMapper.INSTANCE.request2DO(request));
        return true;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean deleteDOById(String ids) {
        Long id = Long.valueOf(ids);
        List<Long> idList = mallIntegrationMapper.selectDOByArticlesId(id);
        if (CollectionUtils.isNotEmpty(idList)){
            List<MallIntegrationOrderDO> integrationOrderDOS = integrationOrderService.lambdaQuery().in(MallIntegrationOrderDO::getMallIntegrationId, idList).list();
            if (CollectionUtils.isNotEmpty(integrationOrderDOS)){
                throw new BusinessException("该书籍已存在积分订单,暂不能删除");
            }
        }
        List<MallBooksOrderDetailsDO> bookOrderList = bookOrderDetailsService.lambdaQuery().eq(MallBooksOrderDetailsDO::getMallBooksId, id).list();
        List<ShoppingCartOrderDetailsDO> cartOrderDetailsDOList = cartOrderDetailsService.lambdaQuery().eq(ShoppingCartOrderDetailsDO::getArticlesId, id).list();
        List<MallBooksDO> booksDOS = this.lambdaQuery().eq(MallBooksDO::getId, id).list();
        booksDOS.forEach(book->{
            Integer onTheShelf = book.getOnTheShelf();
            if (onTheShelf==1){
                throw new BusinessException(ErrorCode.PARAM_ERROR, "商品处于上架状态不能删除!");
            }
        });
        if (CollectionUtils.isNotEmpty(bookOrderList) || CollectionUtils.isNotEmpty(cartOrderDetailsDOList)){
            throw new BusinessException("该书籍已存在订单,暂不能删除");
        }
        if (CollectionUtils.isNotEmpty(idList)){
            throw new BusinessException("该书籍已被积分商品关联,暂不能删除");
        }
        Long count = schoolbagBooksService.lambdaQuery().eq(SchoolbagBooksDO::getMallBooksId, id).count();
        AssertUtil.assertTrue(count == 0, "该书籍已被用于书包书籍，暂不能删除");

        //删除RAS关联数据
        String[] idArray = Convert.toStrArray(ids);
        List<Long> list = Arrays.stream(idArray).map(Long::valueOf).collect(Collectors.toList());
        mallBooksRasService.lambdaUpdate().in(MallBooksRasDO::getMallBooksId,list).remove();
        mallBooksMapper.deleteDOByIds(idArray);
        detailMapper.deleteDOByMallBooksId(idArray);
        booksCategoryMapper.deleteDOByMallBooksId(idArray);
        specificationMapper.deleteDOByMallBooksId(idArray);
        return true;
    }

    @Override
    public PageInfo<List<MallBooksVO>> pagingQuery(MallBooksRequest request, Pageable pageable) {
        List<MallCategoryVO> mallCategoryVOS = mallCategoryService.booksCategory();
        PageHelper.startPage(request.getPageNum(), request.getPageSize(), getOrderBy(pageable.getSort())).setReasonable(true);
        List<MallBooksVO> mallBooksVOS = mallBooksMapper.pagingQuery(request);
        mallBooksVOS.forEach(book->{
            List<Long> mallCategoryIds = book.getMallCategoryIds();
            if (CollectionUtils.isNotEmpty(mallCategoryIds)){
                List<String> categoryNames = new ArrayList<>();
                mallCategoryIds.forEach(id->{
                    mallCategoryVOS.forEach(item->{
                        List<MallCategoryVO> children = item.getChildren();
                        if (CollectionUtils.isNotEmpty(children)){
                            children.forEach(child->{
                                if (child.getId().equals(id)){
                                    categoryNames.add(child.getCategoryName());
                                }
                            });
                        }
                    });
                });
                book.setMallCategoryNames(categoryNames);
            }
        });

        return new PageInfo(mallBooksVOS);
    }

    @Override
    public List<MallBooksVO> selectRandomBooks(Long mallBooksId) {
        List<MallBooksDO> mallBooksDOS =  mallBooksMapper.selectRandomBooks(mallBooksId);
        List<MallBooksVO> mallBooksVOS = MallBooksConvert.buildMallBooksVoList(mallBooksDOS);
        return mallBooksVOS;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean updateDO(MallBooksSaveRequest request) {
        AssertUtil.assertNotNull(request.getId(), "id不能为空!");
        if (request.getOnTheShelf()!=null) {
            if (request.getOnTheShelf() == 1) {
                MallBooksDO booksDO = this.lambdaQuery().eq(MallBooksDO::getId, request.getId()).one();
                Long rasGoodsId = booksDO.getRasGoodsId();
                GoodsListEvidenceRequest evidenceRequest = new GoodsListEvidenceRequest();
                evidenceRequest.setId(rasGoodsId.intValue());
                RasBaseResponse<GoodsListEvidenceResponse> goodsListEvidence = rasClient.goodsListEvidence(evidenceRequest);
                GoodsListEvidenceResponse listEvidenceData = goodsListEvidence.getData();
                GoodsListEvidenceResponse.RasGoodsListPageDTO rasGoodsListPage = listEvidenceData.getRasGoodsListPage();
                List<GoodsListEvidenceResponse.RasGoodsListPageDTO.RecordsDTO> records = rasGoodsListPage.getRecords();
                AssertUtil.assertNotEmpty(records, "该书籍RAS审核还未通过,暂不能上架!");
            }
        }
        saveOrUpdate(MallBooksDtoMapper.INSTANCE.request2DO(request));
        return true;
    }

    @Override
    public List<MallBooksDO> queryByGroupBagId(Long schoolbagGroupBagId) {
        return mallBooksMapper.queryByGroupBagId(schoolbagGroupBagId);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean importBooksExcel(MultipartFile file) {
        long start = System.currentTimeMillis();
        AssertUtil.assertFalse(file.isEmpty(),"文件不能为空!");
        try {
            PoiResult<MallBookExcelDTO> mallBookData =  ExcelHelper.opsParse(MallBookExcelDTO.class)
                    .from(file.getInputStream())
                    // 指定数据区域
                    .opsSheet(0, 1, 0)
                    // 自定义列映射
                    .opsColumn()
                    // 强制输入字符串, 且不能为空
                    .field(Col.A, "mallBooksId").trim().notNull().type(String.class)
                    .field(Col.B, "freeTemplateName").trim().notNull().type(String.class)
                    .field(Col.C, "bookName").trim().notNull().type(String.class)
                    .field(Col.D, "author").trim().notNull().type(String.class)
                    .field(Col.E, "isbn").trim().notNull().type(String.class)
                    .field(Col.F, "publishingHouse").trim().notNull().type(String.class)
                    .field(Col.G, "picture").type(byte[].class).map((val) -> {
                        // 自定义验证，抛异常
                        AssertUtil.assertNotNull(val,"图片不能为空!");
                        return val;
                    })
                    .done()
                    .parse();
            if (mallBookData.hasError()) {
                // 输出验证不通过的信息
                throw new BusinessException("excel文件SHEET1存在如下问题!"+mallBookData.getErrorInfoString());
            }
            PoiResult<MallBookDetailExcelDTO> mallBookDetailData = ExcelHelper.opsParse(MallBookDetailExcelDTO.class)
                    .from(file.getInputStream())
                    // 指定数据区域
                    .opsSheet(1, 1, 0)
                    // 自定义列映射
                    .opsColumn()
                    // 强制输入字符串, 且不能为空
                    .field(Col.A, "mallBooksId").trim().notNull().type(String.class)
                    .field(Col.B, "interest").notNull().type(Integer.class)
                    .field(Col.C, "quality").notNull().type(Integer.class)
                    .field(Col.D, "guide").notNull().type(Integer.class)
                    .field(Col.E, "description").trim().notNull().type(String.class)
                    .field(Col.F, "introduction").trim().notNull().type(String.class)
                    .field(Col.G, "harvest").trim().notNull().type(String.class)
                    .field(Col.H, "ready").trim().notNull().type(String.class)
                    .field(Col.I, "look").trim().notNull().type(String.class)
                    .field(Col.J, "read").trim().notNull().type(String.class)
                    .done()
                    .parse();
            if (mallBookDetailData.hasError()) {
                // 输出验证不通过的信息
                throw new BusinessException("excel文件SHEET2存在如下问题!"+mallBookDetailData.getErrorInfoString());
            }
            PoiResult<MallBookSpecificationExcelDTO> specificationData = ExcelHelper.opsParse(MallBookSpecificationExcelDTO.class)
                    .from(file.getInputStream())
                    // 指定数据区域
                    .opsSheet(2, 1, 0)
                    // 自定义列映射
                    .opsColumn()
                    // 强制输入字符串, 且不能为空
                    .field(Col.A, "mallBooksId").notNull().type(String.class)
                    .field(Col.B, "costPrice").notNull().type(BigDecimal.class)
                    .field(Col.C, "price").notNull().type(BigDecimal.class)
                    .field(Col.D, "vipPrice").notNull().type(BigDecimal.class)
                    .field(Col.E, "specification").notNull().type(String.class)
                    .field(Col.F, "volume").notNull().type(BigDecimal.class)
                    .field(Col.G, "weight").notNull().type(BigDecimal.class)
                    .done()
                    .parse();
            if (specificationData.hasError()) {
                // 输出验证不通过的信息
                throw new BusinessException("excel文件SHEET3存在如下问题!"+specificationData.getErrorInfoString());
            }
            List<MallBookExcelDTO> bookDataList = mallBookData.getData();
            List<MallBookDetailExcelDTO> mallBookDetailList =  mallBookDetailData.getData();
            List<MallBookSpecificationExcelDTO> specificationList = specificationData.getData();
            AssertUtil.assertFalse(CollectionUtils.isEmpty(bookDataList),"导入excel数据为空,请填写后再导入!");
            //查询所有模板
            List<FreeTemplateDO> list = freeTemplateService.lambdaQuery().list();
            List<MallBooksDetailAddRequest> arrayList = new ArrayList<>();
            bookDataList.forEach(book->{
                MallBooksDetailAddRequest request = getMallBooksDetailAddRequest(mallBookDetailList, specificationList, list, book);
                arrayList.add(request);
            });
            this.editing(arrayList);
            long end = System.currentTimeMillis();
            System.out.println("导入完成用时->"+(start-end)+"毫秒");
        }catch (IOException e){
            throw new BusinessException(e.getMessage());
        }
        return true;
    }

    @NotNull
    private MallBooksDetailAddRequest getMallBooksDetailAddRequest(List<MallBookDetailExcelDTO> mallBookDetailList, List<MallBookSpecificationExcelDTO> specificationList, List<FreeTemplateDO> list, MallBookExcelDTO book) {
        byte[] picture = book.getPicture();
        FileInfo upload = fileStorageService.of(picture).upload();
        book.setPictureUrl(upload.getUrl());
        String freeTemplateName = book.getFreeTemplateName();
        FreeTemplateDO templateDO = list.stream().filter(freeTemplateDO -> freeTemplateDO.getTempName().equals(freeTemplateName)).findFirst().orElse(null);
        AssertUtil.assertFalse(templateDO==null,"运费模板名称存在问题!");
        MallBooksDetailAddRequest request = new MallBooksDetailAddRequest();
        //基本信息
        request.setTitle(book.getBookName());
        request.setFreeTemplateId(templateDO.getId());
        request.setAuthor(book.getAuthor());
        request.setIsbnNum(book.getIsbn());
        request.setPublishingHouse(book.getPublishingHouse());
        request.setPicture(book.getPictureUrl());
        request.setOnTheShelf(0);


        //书籍详情
        MallBookDetailExcelDTO detailExcelDTO = mallBookDetailList.stream().filter(bookDetail -> bookDetail.getMallBooksId().equals(book.getMallBooksId())).findFirst().orElse(null);
        AssertUtil.assertFalse(detailExcelDTO==null,"书籍详情存在与书籍不匹配的情况,请检查!");
        request.setInterest(detailExcelDTO.getInterest());
        request.setQuality(detailExcelDTO.getQuality());
        request.setGuide(detailExcelDTO.getGuide());
        request.setDescription(detailExcelDTO.getDescription());
        request.setIntroduction(detailExcelDTO.getIntroduction());
        request.setHarvest(detailExcelDTO.getHarvest());
        request.setLook(detailExcelDTO.getLook());
        request.setRead(detailExcelDTO.getRead());
        request.setReady(detailExcelDTO.getReady());

        //书籍规格
        MallBookSpecificationExcelDTO spec = specificationList.stream().filter(sp -> sp.getMallBooksId().equals(book.getMallBooksId())).findFirst().orElse(null);
        AssertUtil.assertFalse(spec==null,"书籍规格存在与书籍不匹配的情况,请检查!");
        MallBooksSpecificationSaveRequest saveRequest = new MallBooksSpecificationSaveRequest();
        saveRequest.setCostPrice(spec.getCostPrice());
        saveRequest.setPrice(spec.getPrice());
        saveRequest.setVipPrice(spec.getVipPrice());
        saveRequest.setInventory(0L);
        saveRequest.setSpecification(spec.getSpecification());
        saveRequest.setVolume(spec.getVolume());
        saveRequest.setWeight(spec.getWeight());
        List<MallBooksSpecificationSaveRequest> saveRequests = Arrays.asList(saveRequest);
        request.setSpecificationRequests(saveRequests);
        return request;
    }
    private void editing(List<MallBooksDetailAddRequest> req) {
        Long adminUserId = SessionContext.getAdminUserId();
        List<MallBooksDO> bookInfo = new ArrayList<>();
        List<MallBooksDetailDO> bookDetail = new ArrayList<>();
        List<MallBooksSpecificationDO> spes = new ArrayList<>();
        List<Map<String,Object>> maps = new ArrayList<>();
        req.forEach(request->{
            //书籍基本信息
            long id = getId();
            MallBooksSaveRequest mallBooksRequest = new MallBooksSaveRequest();
            mallBooksRequest.setId(id);
            mallBooksRequest.setFreeTemplateId(request.getFreeTemplateId());
            mallBooksRequest.setTitle(request.getTitle());
            mallBooksRequest.setAuthor(request.getAuthor());
            mallBooksRequest.setPublishingHouse(request.getPublishingHouse());
            mallBooksRequest.setPicture(request.getPicture());
            mallBooksRequest.setSortOrder(request.getSortOrder());
            mallBooksRequest.setIsbnNum(request.getIsbnNum());
            mallBooksRequest.setOnTheShelf(0);
            MallBooksDO entity = MallBooksDtoMapper.INSTANCE.request2DO(mallBooksRequest);
            bookInfo.add(entity);
            //书籍详情
            MallBooksDetailRequest detailRequest = new MallBooksDetailRequest();
            detailRequest.setId(getId());
            detailRequest.setId(request.getId());
            detailRequest.setMallBooksId(id);
            detailRequest.setInterest(request.getInterest());
            detailRequest.setQuality(request.getQuality());
            detailRequest.setGuide(request.getGuide());
            detailRequest.setDescription(request.getDescription());
            detailRequest.setIntroduction(request.getIntroduction());
            detailRequest.setHarvest(request.getHarvest());
            detailRequest.setReady(request.getReady());
            detailRequest.setRead(request.getRead());
            detailRequest.setLook(request.getLook());
            detailRequest.setCreateUser(adminUserId);
            MallBooksDetailDO mallBooksDetailDO = MallBooksDetailDtoMapper.INSTANCE.request2DO(detailRequest);
            bookDetail.add(mallBooksDetailDO);
            //规格
            List<MallBooksSpecificationSaveRequest> specificationRequests = request.getSpecificationRequests();
            if (CollectionUtils.isNotEmpty(specificationRequests)) {
                //规格
                specificationRequests.forEach(specification -> {
                    String specification1 = specification.getSpecification();
                    BigDecimal price = specification.getPrice();
                    BigDecimal vipPrice = specification.getVipPrice();
                    BigDecimal volume = specification.getVolume();
                    BigDecimal weight = specification.getWeight();
                    AssertUtil.assertNotNull(specification1,"规格名称不能为空!");
                    AssertUtil.assertNotNull(price,"价格不能为空!");
                    AssertUtil.assertNotNull(vipPrice,"VIP价格不能为空!");
                    AssertUtil.assertNotNull(volume,"体积不能为空!");
                    AssertUtil.assertNotNull(weight,"重量不能为空!");
                    specification.setMallBooksId(id);
                    specification.setId(getId());
                    MallBooksSpecificationDO specificationDO = MallBooksSpecificationDtoMapper.INSTANCE.request2DO(specification);
                    spes.add(specificationDO);
                });
            }
            Map<String, Object> map = new HashMap<>();
            map.put("pic",request.getPicture());
            map.put("title",request.getTitle());
            map.put("id",id);
            maps.add(map);
        });
        List<String> ISBN = bookInfo.stream().map(MallBooksDO::getIsbnNum).collect(Collectors.toList());
        List<MallBooksDO> mallBooksDOS = mallBooksService.lambdaQuery().in(MallBooksDO::getIsbnNum, ISBN).list();
        AssertUtil.assertFalse(CollectionUtils.isNotEmpty(mallBooksDOS),"该类书籍已存在,不可重复添加!");
        long start = System.currentTimeMillis();
        mallBooksMapper.batchInsertDO(bookInfo);
        detailMapper.batchInsertDO(bookDetail);
        specificationMapper.batchInsertDO(spes);
        log.info("书籍数据新增完毕,用时->{}",System.currentTimeMillis()-start+"毫秒");
        List<GoodsAddRequest> addRequests = maps.stream().map(item -> {
            String pic = (String) item.get("pic");
            String title = (String) item.get("title");
            Long id = (Long) item.get("id");
            GoodsAddRequest goodsAddRequest = new GoodsAddRequest();
            goodsAddRequest.setProductName(title);
            goodsAddRequest.setMainImageOfTheProduct(pic);
            goodsAddRequest.setBookId(id);
            return goodsAddRequest;
        }).collect(Collectors.toList());
        long start1 = System.currentTimeMillis();
        RasBaseResponse<Map<Long,Integer>> goodsAdd = rasClient.batchGoodsAdd(addRequests);
        log.info("RAS系统录入完毕,用时->{}",System.currentTimeMillis()-start1+"毫秒");
        Map<Long,Integer> addData = goodsAdd.getData();
        AssertUtil.assertNotNull(addData, "RAS添加商品失败!");
        List<EntryData> list = new ArrayList<>();
        addData.forEach((key,value)->{
            AssertUtil.assertNotNull(value, "RAS服务返回商品ID为空!");
            EntryData entryData = new EntryData(key, Long.valueOf(value));
            list.add(entryData);
        });
        log.info("data->{}",JSONObject.toJSONString(list));
        long start2 = System.currentTimeMillis();
        mallBooksMapper.batchUpdate(list);
        log.info("RAS信息绑定完毕,用时->{}",System.currentTimeMillis()-start2+"毫秒");
    }
}